package com.app.common.net.jl

import com.app.common.net.HttpProtocol
import com.app.common.net.Response
import org.json.JSONObject

class JlApiResponseConverter : HttpProtocol.Converter<Response> {

    override fun onConvert(content: String?): Response {
        if (content == null) {
            return Response()
        }
        return try {
            val jsonObject = JSONObject(content)
            Response(
                jsonObject.optInt("Result"),
                jsonObject.optString("Caption"),
                jsonObject.optInt("Caption Trans Idx"),
                jsonObject
            ).apply {
                body = content
            }
        } catch (e: Exception) {
            e.printStackTrace()
            Response()
        }
    }
}